package com.longshihan.news.control;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.longshihan.news.ui.main.activity.KeepLiveActivity;

import java.lang.ref.WeakReference;

/**
 * @author Administrator
 * @time 2017/3/13 16:18
 * @des 1像素控制器
 * @updateAuthor longshihan
 * @updateDate $Date$
 * @updateDes ${TODO}
 */

public class KeepLiveActivityManager {
    private static KeepLiveActivityManager instance;
    private Context context;
    private WeakReference<Activity> activityInstance;

    public KeepLiveActivityManager(Context context) {
        this.context = context;
    }

    public static KeepLiveActivityManager getInstance(Context context) {
        if(instance==null){
            instance = new KeepLiveActivityManager(context.getApplicationContext());
        }
        return instance;
    }
    public void setKeepLiveActivity(Activity activity){
        activityInstance = new WeakReference<Activity>(activity);
    }

    public void startKeepLiveActivity() {
        Intent intent = new  Intent(context, KeepLiveActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
    public void finishKeepLiveActivity() {
        if(activityInstance!=null&&activityInstance.get()!=null){
            Activity activity = activityInstance.get();
            activity.finish();
        }
    }
}
